set printback=OFF.

TITLE LIS Cross-section Data center in Luxembourg.

TITLE email: usersupport@lisdatacenter.org .

TITLE LIS Self Teaching Package 2022.

TITLE Part I: Inequality, poverty, and social policy.
TITLE SPSS version.

TITLE last change of this version of the syntax: 15-01-2022.

TITLE Exercise 5: Relative poverty rates.

define dataprepare ().  
SET ERRORS OFF. 
compute miss_comp = 0.
if (missing(dhi) or missing(hifactor) or missing(hpub_i) or missing(hpub_u) or missing(hpub_a) or missing(hiprivate) or missing(hxitsc)) miss_comp = 1.
select if miss_comp eq 0.
* select only records if dhi filled. 
select if not missing(dhi) . 
* create top and bottom coded household disposable income.
compute dhi_tb = dhi.
* recode negaive dhi into zero
if (dhi_tb<0) dhi_tb=0.
EXECUTE. 
compute dhi_log = ln(dhi_tb). 
EXECUTE. 
if (missing(dhi_log) & NOT(missing(dhi_tb))) dhi_log=0. 
EXECUTE. 
* create person weight as hwgt times number of household members. 
compute wt = hpopwgt*nhhmem . 
weight by wt. 
!enddefine . 

define decilecalc (). 
preserve .  
set tvars names tnumbers values.  
dataset declare decileratio.  
WEIGHT BY hpopwgt. 
sort cases by did.  
split file by did.  
OMS      
 / select tables      
 / if command = ['Frequencies'] subtypes=['Statistics']      
 /destination format = sav        outfile = 'decileratio'      
 /columns sequence = [l1 r2] .  
frequencies variables = dhi_log 
  /percentiles = 25 50 75 
  /format = notable . 
OMSEND. 
weights off. 
restore. 
match files file = * 
  /table = 'decileratio' 
  /rename (var1 = did) 
  /by did . 
!enddefine .  
 
define topbottom (). 
weight by wt. 
COMPUTE iqr=dhi_log_75-dhi_log_25. 
EXECUTE. 
* detect upper bound for extreme values 
COMPUTE upper_bound=dhi_log_75 + (iqr * 3). 
EXECUTE. 
COMPUTE lower_bound=dhi_log_25 - (iqr * 3). 
EXECUTE. 
* top code income at upper bound for extreme values 
if dhi_tb>exp(upper_bound) dhi_tb=exp(upper_bound).  
EXECUTE. 
* bottom code income at lower bound for extreme values 
if dhi_tb<exp(lower_bound) dhi_tb=exp(lower_bound). 
EXECUTE. 
* create equivalised income, set equivalence scale as square root of household members 
compute edhi_tb = dhi_tb/(nhhmem**0.5).
compute pcdhi_tb = dhi_tb/nhhmem.
!enddefine .

get file = gt06h /keep=did dhi hifactor hpub_i hpub_u hpub_a hiprivate hxitsc hpopwgt nhhmem grossnet.

* run the dataprepare, decilecalc and topbottom
dataprepare.
decilecalc.
topbottom.

compute populat = hpopwgt * nhhmem.
weight by populat.
aggregate outfile = * 
   mode = addvariables 
   /break = did 
   /medianedhi_tb = median(edhi_tb) . 
compute povline = medianedhi_tb * 0.5 . 
descriptives variables = povline . 
compute poor = 0 . 
if edhi_tb lt povline poor = 1 . 
weight by hpopwgt.
frequencies variables = poor . 
weight by populat.
frequencies variables = poor .
